/**
 * SubscribeRequest.java 2008-05-16
 *        
 * Linker is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

package linker.message;

import javax.swing.JOptionPane;

import org.jivesoftware.smack.packet.Presence;

import linker.LocalVariablesManager;
import linker.account.Account;
import linker.list.ViewList;

/**
 * The request message of the other people want to add you.It's used as a
 * message in message list.
 * 
 * AwakenRz:I think this should be merged to another class.
 * 
 * @version 2008-05-16
 * @author Jianfeng tujf.cn@gmail.com
 * 
 */

public class SubscribeRequest extends MessageItem {

	/**
	 * The user want to subscribe.
	 */
	private String user;

	/**
	 * 
	 * @param paraUser
	 *            The user of buddy which want to subscribe.
	 */
	public SubscribeRequest(final String paraUser) {
		super(null, paraUser);
		this.user = paraUser;
	}

	/**
	 * Get String infor.
	 * 
	 * @return The String infor.
	 */
	public final String toString() {
		return "A subcribeRequest";
	}

	/**
	 * DoubleClick event.
	 * 
	 */
	public final void doubleClick() {
		int i = JOptionPane.showConfirmDialog(null, user
				+ " "
				+ LocalVariablesManager
						.getLocalVariables("SubscribeRequestConfirm.Info"),
				LocalVariablesManager
						.getLocalVariables("SubscribeRequestConfirm.Title"),
				JOptionPane.YES_NO_OPTION);

		if (i == JOptionPane.OK_OPTION) {
			Presence presence = new Presence(Presence.Type.subscribed);
			presence.setTo(user);
			// Here need Username with JID
			presence.setFrom(Account.getUserFullID());
			Account.sendPacket(presence);
		} else {
			Presence presence = new Presence(Presence.Type.unsubscribed);
			presence.setTo(user);
			presence.setFrom(Account.getUserFullID());
			Account.sendPacket(presence);
		}

		ViewList.removeMessage(this);
	}

}
